#ifndef MYMODEL_H
#define MYMODEL_H

#include <QAbstractListModel>
#include <QDebug>
#include <QTimer>
#include <QFont>
#include <QFontMetrics>

#include "delegate.h"

#define QT_FILE 0
#define QT_FOLD 1

struct MyData
{
    QString name;
    QString path;
    bool isFold;
    int x;
    bool isSelect = false;
    bool isScroll = false;
    int fontSize = 20;
};
Q_DECLARE_METATYPE(MyData)

class MyModel : public QAbstractListModel
{
    Q_OBJECT

public:
    enum MyRole{
        Role_Name = Qt::DisplayRole + 1,
        Role_Type,
        Role_Path,
        Role_X,
        Role_Select,
        Role_Scroll,
        Role_FontSize,
    };
    static MyModel *Get()
    {
        static MyModel m;
        return &m;
    }

    explicit MyModel(QObject *parent = nullptr);

    // Basic functionality:
    int rowCount(const QModelIndex &parent = QModelIndex()) const override;
    QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;

    void addData(MyData);
    void upadteData(int index, MyData);
    void deleteData(int index);
    void clearData();
    void indexChange(int index);
    int getCurrentIndex(){return currentIndex;}
    int getSize(){return list.size();}
    MyData getCurrentData();
private:
    QList<MyData> list;
    int currentIndex = -1;
    int step = 10;
    QTimer *timer;
};

#endif // MYMODEL_H
